#!/usr/bin/python
# coding=utf-8
import urllib2
import json
import Queue
import time
import os
import sys
import ConfigParser
import random
import hashlib


def POST(url, values):
    headers = {"Content-type": "application/json"}
    jsondata = json.dumps(values)
    request = urllib2.Request(url=url,headers=headers,data=jsondata)
    starttime = time.time()
    try:
        response = urllib2.urlopen(request, data=None, timeout=3)
        endtime = time.time()
        Return = response.read()
        difference = endtime - starttime
        print "调用成功    " + url + "  " + str(difference)
        return Return
    except urllib2.HTTPError, e:
        print "调用失败:"+ url + jsondata
        return {"ret":0}


def GET(url):
    request = urllib2.Request(url)
    starttime = time.time()
    response = urllib2.urlopen(request)
    endtime = time.time()
    Return = response.read()
    difference = endtime - starttime
    print "调用成功    " + url + "  " + str(difference)
    return Return